package com.code.gateway.filter;

import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: Yan
 * @date: 2023/03/29
 */
public class IncludeScanFilter implements TypeFilter {

    public String[] className = {
            "com.code.common.component.SpringContextHolder",
            "com.code.common.config.RedisConfig",
            "com.code.common.exception",
            "com.code.common.handler.GlobalExceptionHandler",
            "com.code.common.model",
            "com.code.common.utils"
    };

    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
        // 可以通过MetadataReader获得各种信息，然后根据自己的需求返回boolean，实例表示包名含有aaa路径的类名将满足筛选条件。
        for (String name : className) {
            return metadataReader.getClassMetadata().getClassName().contains(name);
        }
        return false;
    }

}
